import DynamicData from './DynamicData';
import { ref, watch } from 'vue';
import { watchSwitchLang } from '@/utils/i18n';

// 暴露动态列数据
export const dynamicData = ref(DynamicData());

// 被勾选的动态列数据
export const selectDynamicLabel = ref([]);
// 默认全选
const initSelectDynamicLabel = () => {
  selectDynamicLabel.value = dynamicData.value.map((item) => item.label);
};
initSelectDynamicLabel();
// 国际化
watchSwitchLang(() => {
  dynamicData.value = DynamicData();
  initSelectDynamicLabel();
});

// table列数据
export const tableColumns = ref([]);
watch(
  selectDynamicLabel,
  (val) => {
    tableColumns.value = [];
    // 遍历列数据，判断出当前列是否被勾选
    const selectData = dynamicData.value.filter((item) => {
      return val.includes(item.label);
    });
    tableColumns.value.push(...selectData);
  },
  {
    immediate: true
  }
);
